package com.sc.ktapplication.common.util.RsaUtils;


import java.security.NoSuchAlgorithmException;

public class DeviceSecretUtils {

    /**
     * 生成设备秘钥
     * 秘钥生成规则：日期+设备标识+设备标识+日期 ，MD5处理之后取最后6位字符
     */
    public static String getSecret(String deviceSn, String date){
        String s= null;
        try {
            s = MD5Utils.getMD5(date+deviceSn+deviceSn+date,"utf-8");
            return s.substring(s.length()-6,s.length());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
       return null;
    }


    /**
     * 生成设备LicenseMd5
     * 秘钥生成规则：License+设备标识，MD5处理之后全部小写
     */
    public static String getLicenseMd5(String license, String deviceSn){
        try {
            return MD5Utils.getMD5(license+deviceSn,"utf-8");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }



    public static void main(String args[]){
        String s= null;
        try {
            s = MD5Utils.getMD5("8681B343BB5199499C2730EE55ED36FD8E3992AAF0A053681C9E6BE197B2E09AD74DE6CA5E412E18D84C8EB4C7550CEFFD707FE7FB9610521A54CE795A60E9F41A02B5EA63ACE152366B333AB72023FD7A50DEF8FA2D84E67804412096A360E1C60A4364EC4411432B17D87465BF3369DF9A2B19B84E94456B11B533FCAF7071","utf-8");
            System.out.println(s);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
